﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using System.IO;
using OpenQA.Selenium.IE;
using System.Threading;

namespace Test_WebDriver
{
	/// <summary>
	///		<para>Summary: ...</para>
	///		<para>Author: Heller (Hellersong@outlook.com)</para>
	///		<para>Creation: 3/30/2015 10:23:15 PM</para>
	/// </summary>
	[TestClass]
	public class TestWait
	{
        private static String driverServerPath = "";
        private IWebDriver ieDriver = null;

        [TestInitialize]
        public void Setup()
        {
            String s1 = Directory.GetParent(Environment.CurrentDirectory).ToString();
            String s2 = Directory.GetParent(s1).ToString();
            driverServerPath = s2 + @"\DriverServer\IEDriverServer-64";

        }


		[TestMethod]
		public void test_page_load_title()
		{
            ieDriver = new InternetExplorerDriver(driverServerPath);
            Console.WriteLine("Title Before: " + ieDriver.Title);
            ieDriver.Navigate().GoToUrl(@"http://cn.msn.com/");
            Thread.Sleep(2000);
            Console.WriteLine("Title Loading: " + ieDriver.Title);
            Thread.Sleep(5000);
            Console.WriteLine("Title After: " + ieDriver.Title);

            // Conclusion: Title will not change while loading the page.
		}

		[TestMethod]
        public void test_page_load_status()
        {
            ieDriver = new InternetExplorerDriver(driverServerPath);
			ieDriver.Navigate().Refresh();
            IJavaScriptExecutor js = ieDriver as IJavaScriptExecutor;
			ieDriver.Navigate().GoToUrl(@"http://cn.msn.com/");
			Console.WriteLine("State Before: " + js.ExecuteScript("return document.readyState;").ToString());
			Thread.Sleep(1000);
			Console.WriteLine("State Loading: " + js.ExecuteScript("return document.readyState;").ToString());
			Thread.Sleep(5000);
			Console.WriteLine("State After: " + js.ExecuteScript("return document.readyState;").ToString());
			
        }


        [TestCleanup]
        public void CleanUp()
        {
            ieDriver.Quit();
            ieDriver.Dispose();
        }


	}
}
